<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>个人中心</title>
    <link rel="stylesheet" href="/css/bootstrap.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/plugins/fontawesome-free/css/all.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Tempusdominus Bootstrap 4 -->
    <link rel="stylesheet" href="/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
    <!-- JQVMap -->
    <link rel="stylesheet" href="/plugins/jqvmap/jqvmap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/adminlte.min.css">
    <!-- overlayScrollbars -->
    <link rel="stylesheet" href="/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/plugins/daterangepicker/daterangepicker.css">
    <!-- summernote -->
    <link rel="stylesheet" href="/plugins/summernote/summernote-bs4.min.css">

    <script src="/js/jquery-3.6.1.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">

</head>
<body>

<div class="card card-primary">
    <div class="card-header">
        <h3 class="card-title">我的信息</h3>
    </div>
    <form id="myform" >
        <div class="card-body">
            <input hidden="hidden" id="id" name="id" />
            <div class="form-group">
                <label for="userName">姓名</label>

                <input type="text" class="form-control" id="userName" name="userName" placeholder="Name">
            </div>
            <div class="form-group">
                <label for="userPassword">密码</label>
                <input type="password" class="form-control" id="userPassword" name="userPassword" placeholder="Password">
            </div>
        </div>

        <div class="card-footer">
            <button type="button" class="btn btn-primary" onclick="updateInf();">保存修改</button>
            <button type="button" class="btn btn-primary" onclick="deleteInf();">注销账号</button>

        </div>
    </form>
</div>

<script src="/js/bootstrap.min.js"></script>
<!-- jQuery -->
<script src="/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ChartJS -->
<script src="/plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="/plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="/plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="/plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="/plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="/plugins/moment/moment.min.js"></script>
<script src="/plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="/plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>

<script type="text/javascript">
    let visitorId = localStorage.getItem("key");

    $.ajax({
        url: '/webapi/get/'+visitorId
    }).done(function (rs){
        $('#id').val(rs.id);
        $('#userName').val(rs.userName);
        $('#userPassword').val("*******");
    });



    function updateInf(){
        let data=$("#myform").serialize();
        console.log(data)
        $.ajax({
            url:'/webapi/user/update',
            method:"put",
            data: data
        }).done(function (){
            alert("保存成功！");
            parent.location.reload();
        });
    }


    function deleteInf(){
        let t=confirm("您确认要注销该账号吗？别后悔哦！");
        if(t){
            let id = document.getElementById("id").value;
            //console.log(id)
            $.ajax({
                url:'/webapi/user/delete/'+id,
                method:"delete"
            }).done(function (){

                window.location.href = "/login";
                window.parent.location.href = "/login";

            })
        }
    }
</script>

</body>
</html>